package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppInvitationRecord;
import com.vf.admin.miaodong.entity.AppUser;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 邀请
 */
@Repository
public class AfterInvitationRecordDao extends BaseDao<AppInvitationRecord> {

    /**
     * 详情
     */
    public AppInvitationRecord get(Integer id) {
        if (id==null || id <=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_invitation_record where id = ?  ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppInvitationRecord.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppInvitationRecord appInvitationRecord) {
        if (appInvitationRecord!=null && appInvitationRecord.getId() != null && appInvitationRecord.getId() > 0) {
            this.update(appInvitationRecord);
        } else {
            appInvitationRecord.setId(this.add(appInvitationRecord));
        }
    }


    /**
     * 综合查询列表
     *
     * @param paraMap
     * @param splitPage
     * @return
     */
    public List<AppInvitationRecord> findList(Map<String, Object> paraMap, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("SELECT * FROM app_invitation_record  where 1=1");
        if (StringEx.isNotNull(paraMap.get("userid"))) {
            sbStr.append(" and puserid = ? ");
            paramList.add(paraMap.get("userid"));
        }
        if (StringEx.isNotNull(paraMap.get("pnick"))) {
            sbStr.append(" and pnick like ? ");
            paramList.add("%" + paraMap.get("pnick") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("pphone"))) {
            sbStr.append(" and pphone like ? ");
            paramList.add("%" + paraMap.get("pphone") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("start"))) {
            sbStr.append(" and start = ? ");
            paramList.add(paraMap.get("start"));
        }
        if (!StringEx.isNull(paraMap.get("startDate"))) {
            sbStr.append(" and createtime>=? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (!StringEx.isNull(paraMap.get("endDate"))) {
            sbStr.append(" and createtime<=? ");
            paramList.add(paraMap.get("endDate"));
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppInvitationRecord.class, splitPage);
    }
}
